package com.example.tliasmanagement.service.impl;

import com.example.tliasmanagement.mapper.EmpMapper;
import com.example.tliasmanagement.mapper.StudentMapper;
import com.example.tliasmanagement.service.ReportService;
import com.example.tliasmanagement.vo.EmpJobDataVo;
import com.example.tliasmanagement.vo.NameValueVo;
import com.example.tliasmanagement.vo.StudentNumberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    /**
     *  统计员工职位信息
     * */
    @Override
    public EmpJobDataVo empJobData() {
        // 从数据库查
        List<NameValueVo> voList = empMapper.empJobData();
        if (CollectionUtils.isEmpty(voList)) {
            return new EmpJobDataVo();
        }
        // 结果组装
        List<String> jobList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        for (NameValueVo nameValueVo : voList) {
            String title = nameValueVo.getName();
            Integer value = nameValueVo.getValue();
            jobList.add(title);
            dataList.add(value);
        }
        EmpJobDataVo vo = new EmpJobDataVo();
        vo.setDataList(dataList);
        vo.setJobList(jobList);
        return vo;
    }
    /**
     *  统计员工性别信息
     * */
    @Override
    public List<NameValueVo> empGenderData() {
        return empMapper.empGenderData();
    }
    /**
     *  统计班级人数信息
     * */
    @Override
    public StudentNumberVo studentCountData(){
        List<NameValueVo> voList = studentMapper.studentCountData();
        if (CollectionUtils.isEmpty(voList)) {
            return new StudentNumberVo();
        }
        List<String> clazzList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        for (NameValueVo nameValueVo : voList) {
            String title = nameValueVo.getName();
            Integer value = nameValueVo.getValue();
            clazzList.add(title);
            dataList.add(value);
        }
        StudentNumberVo vo = new StudentNumberVo();
        vo.setDataList(dataList);
        vo.setClazzList(clazzList);
        return vo;
    }
    /**
     *  统计班级学历信息
     * */
    @Override
    public List<NameValueVo> studentDegreeData(){
        return studentMapper.studentDegreeData();
    }
}
